package cn.wzptsoft.tinymallbe.service;

import cn.wzptsoft.tinymallbe.entity.Category;
import cn.wzptsoft.tinymallbe.entity.Theme;
import cn.wzptsoft.tinymallbe.repository.CategoryRepository;
import cn.wzptsoft.tinymallbe.repository.ThemeRepository;
import cn.wzptsoft.tinymallbe.vo.CategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryRepository categoryRepository;

    public CategoryVO getAll() {
//        查找所有根分类
        List<Category> roots = categoryRepository.findByIsRootOrderBySortAsc(true);
//        查找所有非根分类
        List<Category> subs = categoryRepository.findByIsRootOrderBySortAsc(false);
//      roots和subs整合到VO类
        CategoryVO result = new CategoryVO();
        result.setRoots(roots);
        result.setSubs(subs);
        return result;
    }

    public List<Category> getRootCategory() {
        List<Category> roots = categoryRepository.findByIsRootOrderBySortAsc(true);
        return roots;
    }
}
